package com.lanxin.hr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lanxin.hr.entity.ZzExprience;
import com.lanxin.hr.mapper.ZzExprienceMapper;
import com.lanxin.hr.service.IZzExprienceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-07-26
 */
@Service
public class ZzExprienceServiceImpl extends ServiceImpl<ZzExprienceMapper, ZzExprience> implements IZzExprienceService {

    @Autowired
    private ZzExprienceMapper exprienceMapper;

    //根据员工id获取工作经历
    @Override
    public List<ZzExprience> getExprienceByEid(Integer eid) {
        QueryWrapper<ZzExprience> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("empid",eid);
        return exprienceMapper.selectList(queryWrapper);
    }

    //更新工作经验,
    @Override
    public int updateExprienceById(Integer eid,List<ZzExprience> expriences) {
        //删除旧的
        exprienceMapper.deleteById(eid);
        for (ZzExprience exprience : expriences) {
            exprience.setEmpid(eid);
        }
        //添加新的
        int row = 0;
        for (ZzExprience exprience : expriences) {
            row = row + exprienceMapper.insert(exprience);
        }
        return row;
    }


    //删除工作经验
    @Override
    public int deleteExperienceById(Integer eid) {
        QueryWrapper<ZzExprience> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("empid",eid);
        return exprienceMapper.delete(queryWrapper);
    }
}
